package com.roam.cofig;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
@ConfigurationProperties(prefix = "spring.data.redis")
public class RedissonConfig {
    private String host;
    private String port;
    private String password;
    private int database;
    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        String redisAddress=String.format("redis://%s:%s",host,port);
        //setdatabase指定redis库号
        config.useSingleServer().setAddress(redisAddress).setDatabase(database).setPassword(password);
        //创建实例
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
